import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ColorProcessor;
import ij.process.ImageProcessor;
import color.LabColorSpace;

/* This plugin increases the luminance (brightness) in Lab space */

public class Color_Lab_Test implements PlugInFilter {

	public int setup(String arg, ImagePlus imp) {
		return DOES_RGB;
	}

	public void run(ImageProcessor ip) {
		ColorProcessor cp = (ColorProcessor) ip;
		int[] RGB = new int[3];
		float[] rgb = new float[3];
		
		LabColorSpace lcs = new LabColorSpace(); 
		
		for (int v = 0; v < cp.getHeight(); v++) {
			for (int u = 0; u < cp.getWidth(); u++) {
				cp.getPixel(u, v, RGB);
				
				rgb[0] = RGB[0] / 255.0f;
				rgb[1] = RGB[1] / 255.0f;
				rgb[2] = RGB[2] / 255.0f;
				
				float[] lab = lcs.fromRGB(rgb);	// convert sRGB -> Lab
				lab[0] = lab[0] * 1.25f;		// increase luminance by 25%
				float[] rgb2 = lcs.toRGB(lab);	// convert Lab -> sRGB
				
				RGB[0] = Math.round(rgb2[0] * 255);
				RGB[1] = Math.round(rgb2[1] * 255);
				RGB[2] = Math.round(rgb2[2] * 255);

				cp.putPixel(u, v, RGB);
			}
		}
	}
}